package World.Module.EventSystem;

import Collections.UnOrderMultiMap;

import java.util.ArrayList;
import java.util.HashMap;

public class TypeSystems {

    public class OneTypeSystems
    {

        public final UnOrderMultiMap<Class<?>, Object> Map = new UnOrderMultiMap<>();
        public final boolean[] QueueFlag;
        public OneTypeSystems(int count)
        {
            this.QueueFlag = new boolean[count];
        }
    }

    private final int count;

    public TypeSystems(int count)
    {
        this.count = count;
    }

    private final HashMap<Class<?>, OneTypeSystems> typeSystemsHashMap = new HashMap<>();

    public OneTypeSystems GetOrCreateOneTypeSystems(Class<?> type)
    {
        OneTypeSystems systems = this.typeSystemsHashMap.get(type);
        if(systems != null)
        {
            return systems;
        }
        else
        {
            systems = new OneTypeSystems(this.count);
            this.typeSystemsHashMap.put(type, systems);
            return systems;
        }
    }

    public OneTypeSystems GetOneTypeSystems(Class<?> type)
    {
            return this.typeSystemsHashMap.get(type);
    }

    public ArrayList<Object> GetSystems(Class<?>  type, Class<?>  systemType)
    {
        OneTypeSystems oneTypeSystems = this.typeSystemsHashMap.get(type);
        if(oneTypeSystems == null)
            return null;

        ArrayList<Object> systems = oneTypeSystems.Map.Get(systemType);
        if (systems == null)
        {
            return null;
        }
        return systems;
    }

}
